﻿#region File and License Information
/*
<File>
	<License>
		Copyright © 2009 - 2017, Daniel Vaughan. All rights reserved.
		This file is part of Calcium (http://calciumsdk.net), 
		which is released under the MIT License.
		See file /Documentation/License.txt for details.
	</License>
	<CreationDate>2010-03-25 20:41:44Z</CreationDate>
</File>
*/
#endregion

using System;

namespace Outcoder.ComponentModel
{
	/// <summary>
	/// Converts a value of type TFrom to a value of type TTo.
	/// </summary>
	/// <typeparam name="TFrom">The type converted from.</typeparam>
	/// <typeparam name="TTo">The type converted to.</typeparam>
	public interface IConverter<TFrom, TTo>
	{
		TTo Convert(TFrom fromValue);
	}

	/// <summary>
	/// Simple implementation of the IConverter, using the object type.
	/// </summary>
	public interface IConverter : IConverter<object, object>
	{
		/* Intentionally left blank. */
	}

	public class DelegateConverter : IConverter
	{
		readonly Func<object, object> convertFunc;

		public DelegateConverter(Func<object, object> convertFunc)
		{
			this.convertFunc = ArgumentValidator.AssertNotNull(convertFunc, "convertFunc");
		}

		public object Convert(object fromValue)
		{
			var result = convertFunc(fromValue);
			return result;
		}
	}
}
